package com.loozb.intstream;

import java.util.stream.IntStream;

/**
 * 流
 *
 * @author 龙召碧
 * @create 2018-07-02 11:41
 **/
public class IntStreamMain {

    /**
     * 测试循环500次，每次休眠1毫秒
     * 测试结果：
     * 耗时1：640
     * 耗时2:2252
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception{
        //一万次执行
        long s = System.currentTimeMillis();
        IntStream.range(0,500).parallel().forEach(i -> {
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        long e = System.currentTimeMillis();
        long j = e-s;


        long s1 = System.currentTimeMillis();
        for (int k = 0; k < 500; k++) {
            try {
                Thread.sleep(1);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
        }
        long e1 = System.currentTimeMillis();
        long j1 = e1-s1;
        System.out.println("耗时1：" + j);
        System.out.println("耗时2:" + j1);
    }
}
